<template>
	<u-popup v-model="show" mode="center" width="500rpx" height="80%" :closeable="true">
		<view class="list">
			<u-card :show-head="false" padding="30" margin="0" :border="false" :foot-border-top="false"
				v-for="(item,index) in ramkingList" :key="index">
				<view class="" slot="body">
					<view class="ranking-body-item"
						:class="{'border-red':index != 0 && carrierRanking === item.ranking}">
						<view class="title" :class="{'carrierRanking':index != 0 || carrierRanking === ''}">
							<view class="ranking" v-if="index != 0 || carrierRanking === ''">
								{{item.ranking}}
							</view>
							<view class="carrierName">{{item.carrierName}}</view>
						</view>
						<view class="info">
							<view class="info-item" v-if="index === 0 && carrierRanking!=''">
								<view>我的排名:</view>
								<view class="number red">{{item.ranking}}</view>
							</view>
						</view>
					</view>
				</view>
			</u-card>
		</view>
	</u-popup>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				id: '',
				ramkingList: [],
				carrierRanking: ''
			}
		},
		methods: {
			// 开启弹窗
			open(id) {
				this.show = true;
				this.id = id;
				this.getList();
			},
			getList() {
				this.ramkingList = []
				this.carrierRanking = ''
				uni.showLoading({
					title: '加载中'
				})
				this.$u.api.carrier.getRankingList({
					id: this.id,
				}).then(data => {
					uni.hideLoading()
					if (data.code === 200 && data.success) {
						this.ramkingList = data.data.viewRankingRespVOS;
						if (data.data.viewRankingVO.carrierName) {
							this.ramkingList.unshift({
								...data.data.viewRankingVO
							});
							this.carrierRanking = data.data.viewRankingVO.ranking;
						}
					}
				}).catch(() => {
					uni.hideLoading()
				})
			},
		}
	}
</script>

<style lang="less">
	.list {
		margin-top: 60rpx;

		.ranking-body-item {
			font-size: 28rpx;
			color: #333;
			width: 100%;
			padding: 40rpx 20rpx;
			box-sizing: border-box;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border: 1rpx solid #d4d4d4;
			border-radius: 16rpx;

			.title {
				width: 50%;
				display: flex;

				.carrierName {
					width: 80%;
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
				}

				.ranking {
					color: red;
					margin-right: 10rpx;
				}
			}

			.carrierRanking {
				width: 100%;
			}

			.info {
				height: 90rpx;
				display: flex;
				justify-content: space-between;
				flex-direction: column;

				.info-item {
					display: flex;

					.number {
						min-width: 60rpx;
						text-align: center;
					}

					.red {
						color: red;
					}
				}
			}
		}

		.border-red {
			// border-color: red;
		}
	}
</style>
